package com.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.action.InstrumentAction;
import com.bean.InstrumentBean;
import com.exception.DBException;
import com.exception.InstrumentException;
import com.util.HandleInfo;
import com.util.Regex;
import com.util.StateInfo;

public class InstrumentDetailServlet extends HttpServlet
{

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		String barcode = request.getParameter("barcode");
		if(null == barcode)
		{
			HandleInfo.handle(request, response,  
					StateInfo.INNER_CONFIRM_FAIL);
			return;
		}
		if ("".equals(barcode))
		{
			HandleInfo.handle(request, response,  
					StateInfo.INNER_CONFIRM_FAIL);
			return;
		}
		if (!Regex.checkBarcode(barcode))
		{
			HandleInfo.handle(request, response,  
					StateInfo.INNER_CONFIRM_FAIL);
			return;
		}
		InstrumentBean insBean = new InstrumentBean();
		insBean.setBarcode(barcode);
		try
		{
			new InstrumentAction().detailInstrument(request, response, insBean);
		}
		catch (DBException e)
		{
			HandleInfo.handle(request, response, e.getMessage());
			return;
		}
		catch (InstrumentException e)
		{
			HandleInfo.handle(request, response, e.getMessage());
			return;
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		doGet(request, response);
	}

}
